/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * AdminFilmType.java
 *
 * Created on Apr 27, 2012, 3:58:30 PM
 */
package GUI.Admin;

import dao.LoaiPhimDAO;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.List;
import java.util.Vector;
import javax.swing.ActionMap;
import javax.swing.JOptionPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.table.DefaultTableModel;
import org.jdesktop.application.Action;
import org.jdesktop.application.Application;
import org.jdesktop.application.SingleFrameApplication;
import org.jdesktop.application.Task;
import pojo.Loaiphim;
import utils.BusyIndicator;
import utils.BusyIndicatorInputBlocker;
import utils.ClassUtils;

/**
 *
 * @author Hnmtuan
 */
public class AdminFilmType extends javax.swing.JPanel {

    // <editor-fold defaultstate="collapsed" desc="Define all variables using this application">
    SingleFrameApplication localApplication;
    BusyIndicator localBusy;
    ActionMap _rsActionMap;
    DefaultTableModel _filmTypesModel;
    List<Loaiphim> _filmTypes;
    private boolean saveNeeded, cancelSelected, newRow;
    String DEFAULT_SEARCH_STRING;
    // </editor-fold>
    //<editor-fold defaultstate="collapsed" desc="Define messages and error messages" >
    private final String MSG_EMPTY = "";
    private final String MSG_SAVE_SUCCESS = "Insert film type successfully";
    private final String MSG_SAVE_BEGINNING = "Begin saving .... !";
    private final String MSG_SAVE_DATABASE = "Saving database  .... !";
    private final String MSG_UPDATE_SUCCESS = "Update film type successfully";
    private final String MSG_UPDATE_BEGINNING = "Begin updating .... !";
    private final String MSG_UPDATE_DATABASE = "Updating database  .... !";
    private final String MSG_DELETE_SUCCESS = "Delete film type successfully";
    private final String MSG_DELETE_BEGINNING = "Begin deleteing .... !";
    private final String MSG_DELETE_DATABASE = "Deleteing database  .... !";
    private final String MSG_DELETE_CONFIRM = "Do you want to delete %s ?";
    private final String MSG_DELETE_TITLE = "Delete Film Type";
    private final String MSG_SEARCH_BEGINNING = "Begin searching .... !";
    private final String MSG_SEARCH_SUCCESS = "Search successfully .... !";
    private final String MSG_LOADING = "Reloading list film types  .... !";
    private final String ERR_LIST_EMPTY = "Type list is empty";
    private final String ERR_SELECTED_TYPE_EMPTY = "Selected type is empty";
    private final String ERR_SAVE_TASK = "Save task not done !";
    private final String ERR_SELECT_OUTOFBOUND = "You select out of bound !";
    private final String ERR_UPDATE_TASK = "Update task not done !";
    private final String ERR_UPDATE_INVALID_PARAMS = "Update invalid parameters !";
    private final String ERR_DELETE_TASK = "Delete task not done !";
    private final String ERR_DELETE_INVALID_PARAMS = "Delete invalid parameters !";
    private final String ERR_SEARCH_INVALID_PARAMS = "Search invalid parameters !";
    private final String ERR_SEARCH_INVALID_SOURCES = "Source search empty !";
    private final String ERR_SEARCH_TASK = "Search task not done !";
    private final String ERR_SEARCH_NOT_FOUND = "%s not found !";
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Constructor" >

    public AdminFilmType(SingleFrameApplication appContext, BusyIndicator busy) throws Exception {
        localApplication = appContext;
        localBusy = busy;
        initComponents();
        initActions();
        loadFilmTypes();
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Init Actions" >

    private void initActions() throws Exception {
        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("GUI/Admin/resources/AdminFilmType");
        _rsActionMap = Application.getInstance(main.MainFormApp.class).getContext().getActionMap(getClass(), this);
        jbtnSearch.setAction(_rsActionMap.get("searchFilmType"));
        jbtnUpdateType.setAction(_rsActionMap.get("updatedRow"));
        jbtnDeleteType.setAction(_rsActionMap.get("deletedRow"));
        jbtnCancel.setAction(_rsActionMap.get("cancelRow"));
        jbtnAddType.setAction(_rsActionMap.get("addRow"));
        jbtnReset.setAction(_rsActionMap.get("resetRow"));
        DEFAULT_SEARCH_STRING = bundle.getString("jtfSearchForm.title");
        jtxtSearch.addMouseListener(new MouseAdapter() {

            // Compsite of two actions Press and Release
            @Override
            public void mouseClicked(MouseEvent e) {
                String searchText = jtxtSearch.getText();
                // if text field empty so on ...
                if (searchText.equalsIgnoreCase(DEFAULT_SEARCH_STRING)) {
                    jtxtSearch.setText("");
                }
            }

            @Override
            public void mouseExited(MouseEvent e) {
                String searchText = jtxtSearch.getText();
                // if texfield empty so write default text for it
                if (searchText.equalsIgnoreCase("")){
                    jtxtSearch.setText(DEFAULT_SEARCH_STRING);
                }
                // else nothing else ..
            }
        });
        jtbFilmTypes.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            // -->>> not revoiked event throws exception

            public void valueChanged(ListSelectionEvent e) {
                if (isRecordSelected()) {
                    loadFields();
                }
                firePropertyChange("recordSelected", !isRecordSelected(), isRecordSelected());
                setSaveNeeded(true);
                setCancelSelected(true);
                setNewRow(false);
            }
        });
        setNewRow(true);
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Implement All Actions">
    @Action
    public Task searchFilmType() {
        Task task = new SearchTask(this.localApplication);
        task.setInputBlocker(new BusyIndicatorInputBlocker(task, this.localBusy));
        return task;
    }

    @Action(enabledProperty = "recordSelected")
    public Task deletedRow() {
        Task task = new DeleteTask(this.localApplication);
        task.setInputBlocker(new BusyIndicatorInputBlocker(task, this.localBusy));
        return task;
    }

    @Action(enabledProperty = "saveNeeded")
    public Task updatedRow() {
        Task task = new UpdateTask(this.localApplication);
        task.setInputBlocker(new BusyIndicatorInputBlocker(task, this.localBusy));
        return task;
    }

    @Action(enabledProperty = "cancelSelected")
    public void cancelRow() {
        defaultButtonState();
    }

    @Action(enabledProperty = "newRow")
    public Task addRow() {
        Task task = new SaveTask(this.localApplication);
        task.setInputBlocker(new BusyIndicatorInputBlocker(task, this.localBusy));
        return task;
    }

    @Action
    public void resetRow() {
        clearAllTextField();
    }

    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Implement All Property or State">
    public boolean isCancelSelected() {
        return cancelSelected;
    }

    public boolean isSaveNeeded() {
        return saveNeeded;
    }

    public boolean isNewRow() {
        return newRow;
    }

    public boolean isRecordSelected() {
        return jtbFilmTypes.getSelectedRow() != -1;
    }

    public void setSaveNeeded(boolean saveNeeded) {
        if (saveNeeded != this.saveNeeded) {
            this.saveNeeded = saveNeeded;
            firePropertyChange("saveNeeded", !this.saveNeeded, this.saveNeeded);
        }
    }

    public void setCancelSelected(boolean cancelSelected) {
        if (cancelSelected != this.cancelSelected) {
            this.cancelSelected = cancelSelected;
            firePropertyChange("cancelSelected", !this.cancelSelected, this.cancelSelected);
        }
    }

    public void setNewRow(boolean newRow) {
        if (newRow != this.newRow) {
            this.newRow = newRow;
            firePropertyChange("newRow", !this.newRow, this.newRow);
        }
    }

    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Implement Actions to GUI" >
    protected final void clearAllTextField() {
        jtfCodeId.setText(MSG_EMPTY);
        jtfTypeName.setText(MSG_EMPTY);
        jtaDetailDescription.setText(MSG_EMPTY);
    }

    protected final void defaultButtonState() {
        clearAllTextField();
        jtbFilmTypes.clearSelection();
        firePropertyChange("recordSelected", isRecordSelected(), !isRecordSelected());
        setSaveNeeded(false);
        setCancelSelected(false);
        setNewRow(true);
    }

    protected final void loadFields() {
        try {
            if (_filmTypes == null) {
                throw new Exception(ERR_LIST_EMPTY);
            }
            int maxSize = _filmTypes.size();
            int selectedRow = jtbFilmTypes.getSelectedRow(); //row which you select into JTable
            if (selectedRow > maxSize) {
                throw new Exception(ERR_SELECT_OUTOFBOUND);
            }
            Loaiphim selectedType = _filmTypes.get(selectedRow);
            if (selectedType == null) {
                throw new Exception(ERR_SELECTED_TYPE_EMPTY);
            }
            jtfCodeId.setText(selectedType.getCodeLoaiPhim());
            jtfTypeName.setText(selectedType.getTenLoaiPhim());
            jtaDetailDescription.setText(selectedType.getMoTa());
        } catch (Exception e) {
            //System.out.println(String.format("Error: %s", e.getMessage()));
            e.printStackTrace(); //-->>> show remove this code
        }

    }

    protected final void loadFilmTypes() throws Exception {
        _filmTypesModel = (DefaultTableModel) jtbFilmTypes.getModel();
        _filmTypesModel.getDataVector().clear();
        try {
            _filmTypes = LoaiPhimDAO.getLoaiPhims();
            if (_filmTypes == null) {
                throw new Exception(ERR_LIST_EMPTY);
            }
            int count = 0;
            for (Loaiphim loaiphim : _filmTypes) {
                Vector v = new Vector();
                count = count + 1;
                v.addElement(count);
                v.addElement(loaiphim.getCodeLoaiPhim());
                v.addElement(loaiphim.getTenLoaiPhim());
                _filmTypesModel.addRow(v);
            }
            jtbFilmTypes.setModel(_filmTypesModel);
        } catch (Exception ex) {
            throw new Exception(ex.getMessage());
        }
    }

    protected final int getFilmTypeByCode(String code) throws Exception {
        if (code.isEmpty()) {
            throw new Exception(ERR_SEARCH_INVALID_PARAMS);
        }
        if (_filmTypes == null || _filmTypes.size() < 1) {
            throw new Exception(ERR_SEARCH_INVALID_SOURCES);
        }
        int searchIndex = -1;
        int maxSize = _filmTypes.size();
        for (Loaiphim loaiphim : _filmTypes) {
            searchIndex++;
            if (loaiphim.getCodeLoaiPhim().equalsIgnoreCase(code)) {
                return searchIndex;
            }
        }
        return searchIndex = (searchIndex == maxSize - 1) ? -1 : searchIndex;
    }

    protected final int getFilmTypeByName(String name) throws Exception {
        if (name.isEmpty()) {
            throw new Exception(ERR_SEARCH_INVALID_PARAMS);
        }
        if (_filmTypes == null || _filmTypes.size() < 1) {
            throw new Exception(ERR_SEARCH_INVALID_SOURCES);
        }
        int searchIndex = -1;
        int maxSize = _filmTypes.size();
        for (Loaiphim loaiphim : _filmTypes) {
            searchIndex++;
            if (loaiphim.getTenLoaiPhim().equalsIgnoreCase(name)) {
                return searchIndex;
            }
        }
        return searchIndex = (searchIndex == maxSize - 1) ? -1 : searchIndex;
    }

    protected final void setSelectedRowFilmTypes(int index) {
        if (index == -1) {
            return;
        }
        jtbFilmTypes.changeSelection(index, 0, false, false);
    }

    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Search Task" >
    private class SearchTask extends Task<Void, Void> {

        public SearchTask(SingleFrameApplication appContext) {
            super(appContext);
        }

        @Override
        protected Void doInBackground() throws Exception {
            setMessage(MSG_SEARCH_BEGINNING);
            Thread.sleep(150L);
            setProgress(1, 0, 3);
            // Check text field to input text not empty or default text
            String searchField = jtxtSearch.getText();
            int resultIndex = -1;
            // Check option search to be checked
            if (jrdByCode.isSelected()) {
                resultIndex = getFilmTypeByCode(searchField);
            } else if (jrdByName.isSelected()) {
                resultIndex = getFilmTypeByName(searchField);
            }
            // Get object is selected
            if (resultIndex == -1) {
                throw new Exception(String.format(ERR_SEARCH_NOT_FOUND, searchField));
            }
            // Search database
            setSelectedRowFilmTypes(resultIndex);
            // Loading GUI
            setMessage(MSG_LOADING);
            Thread.sleep(150L);
            setProgress(2, 0, 3);

            return null;
        }

        @Override
        protected void cancelled() {
            setMessage(ERR_SEARCH_TASK);
        }

        @Override
        protected void failed(Throwable thrwbl) {
            setMessage(thrwbl.getMessage());
            clearAllTextField();
            defaultButtonState();
        }

        @Override
        protected void succeeded(Void t) {
            setMessage(MSG_SEARCH_SUCCESS);
            setProgress(3, 0, 3);
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Delete Task" >
    private class DeleteTask extends Task<Void, Void> {

        public DeleteTask(SingleFrameApplication appContext) {
            super(appContext);
        }

        @Override
        protected Void doInBackground() throws Exception {
            setMessage(MSG_DELETE_BEGINNING);
            Thread.sleep(150L);
            setProgress(1, 0, 4);
            // Get object is selected to delete
            int selectedIndex = jtbFilmTypes.getSelectedRow();
            if (_filmTypes == null || selectedIndex == -1) {
                throw new Exception(ERR_DELETE_INVALID_PARAMS);
            }
            Loaiphim cachedFilmType = _filmTypes.get(selectedIndex);
            String msg = String.format(MSG_DELETE_CONFIRM, cachedFilmType.getCodeLoaiPhim());
            int returnOptionDialog = JOptionPane.showConfirmDialog(localApplication.getMainFrame(), msg, MSG_DELETE_TITLE, JOptionPane.OK_CANCEL_OPTION);
            if (returnOptionDialog == JOptionPane.CANCEL_OPTION) {
                return null;
            }
            setMessage(MSG_DELETE_DATABASE);
            Thread.sleep(150L);
            setProgress(2, 0, 4);
            // Delete database
            LoaiPhimDAO.deleteLoaiPhims(cachedFilmType);
            // Loading GUI
            setMessage(MSG_LOADING);
            Thread.sleep(150L);
            setProgress(3, 0, 4);
            loadFilmTypes();
            Thread.sleep(150L);
            return null;
        }

        @Override
        protected void cancelled() {
            setMessage(ERR_DELETE_TASK);
        }

        @Override
        protected void failed(Throwable thrwbl) {
            setMessage(thrwbl.getMessage());
        }

        @Override
        protected void succeeded(Void t) {
            clearAllTextField();
            defaultButtonState();
            setMessage(MSG_DELETE_SUCCESS);
            setProgress(4, 0, 4);
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Update Task" >
    private class UpdateTask extends Task<Void, Void> {

        public UpdateTask(SingleFrameApplication appContext) {
            super(appContext);
        }

        @Override
        protected Void doInBackground() throws Exception {
            setMessage(MSG_UPDATE_BEGINNING);
            Thread.sleep(150L);
            setProgress(1, 0, 4);
            // Get information and prepare object
            int selectedIndex = jtbFilmTypes.getSelectedRow();
            if (_filmTypes == null || selectedIndex == -1) {
                throw new Exception(ERR_UPDATE_INVALID_PARAMS);
            }
            Loaiphim cachedFilmType = _filmTypes.get(selectedIndex);
            cachedFilmType.setCodeLoaiPhim(jtfCodeId.getText());
            cachedFilmType.setTenLoaiPhim(jtfTypeName.getText());
            cachedFilmType.setMoTa(jtaDetailDescription.getText());

            setMessage(MSG_UPDATE_DATABASE);
            Thread.sleep(150L);
            setProgress(2, 0, 4);
            // Update to database
            LoaiPhimDAO.updateLoaiPhims(cachedFilmType);
            // Loading gui
            setMessage(MSG_LOADING);
            Thread.sleep(150L);
            setProgress(3, 0, 4);
            loadFilmTypes();
            Thread.sleep(150L);
            return null;
        }

        @Override
        protected void cancelled() {
            setMessage(ERR_UPDATE_TASK);
        }

        @Override
        protected void failed(Throwable thrwbl) {
            setMessage(thrwbl.getMessage());
        }

        @Override
        protected void succeeded(Void t) {
            clearAllTextField();
            defaultButtonState();
            setMessage(MSG_UPDATE_SUCCESS);
            setProgress(4, 0, 4);
        }
    }
    // </editor-fold>
    // <editor-fold defaultstate="collapsed" desc="Define Save Task" >

    private class SaveTask extends Task<Void, Void> {

        public SaveTask(SingleFrameApplication appContext) {
            super(appContext);
        }

        @Override
        protected Void doInBackground() throws Exception {
            // Get all information from fields
            setMessage(MSG_SAVE_BEGINNING);
            Thread.sleep(150L);
            setProgress(1, 0, 4);
            String codeFilmType = jtfCodeId.getText();
            String nameFilmType = jtfTypeName.getText();
            String descriptFilmType = jtaDetailDescription.getText();
            Loaiphim cachedFilmType = new Loaiphim(codeFilmType, nameFilmType, descriptFilmType,
                    ClassUtils.StateFields.DEFAULT_STATUS, null);
            setMessage(MSG_SAVE_DATABASE);
            Thread.sleep(150L);
            setProgress(2, 0, 4);
            LoaiPhimDAO.insertLoaiPhims(cachedFilmType);
            setMessage(MSG_LOADING);
            Thread.sleep(150L);
            setProgress(3, 0, 4);
            loadFilmTypes();
            Thread.sleep(150L);
            return null;
        }

        @Override
        protected void cancelled() {
            setMessage(ERR_SAVE_TASK);
        }

        @Override
        protected void failed(Throwable thrwbl) {
            setMessage(thrwbl.getMessage());
        }

        @Override
        protected void succeeded(Void t) {
            setMessage(MSG_SAVE_SUCCESS);
            setProgress(4, 0, 4);
            clearAllTextField();
            defaultButtonState();
        }
    }
    // </editor-fold>

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        bgSearchOptions = new javax.swing.ButtonGroup();
        jpSearchFilmType = new javax.swing.JPanel();
        jtxtSearch = new javax.swing.JTextField();
        jbtnSearch = new javax.swing.JButton();
        jrdByCode = new javax.swing.JRadioButton();
        jrdByName = new javax.swing.JRadioButton();
        jpListFilmType = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtbFilmTypes = new javax.swing.JTable();
        jpDetailFilmType = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jtfCodeId = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jtfTypeName = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtaDetailDescription = new javax.swing.JTextArea();
        jbtnReset = new javax.swing.JButton();
        jbtnAddType = new javax.swing.JButton();
        jbtnUpdateType = new javax.swing.JButton();
        jbtnDeleteType = new javax.swing.JButton();
        jbtnCancel = new javax.swing.JButton();

        java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("GUI/Admin/resources/AdminFilmType"); // NOI18N
        jpSearchFilmType.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("jpSearchForm.title"))); // NOI18N
        jpSearchFilmType.setName("jpSearchFilmType"); // NOI18N

        jtxtSearch.setText(bundle.getString("jtfSearchForm.title")); // NOI18N
        jtxtSearch.setName("jtxtSearch"); // NOI18N

        jbtnSearch.setText(bundle.getString("jbtnSearch.title")); // NOI18N
        jbtnSearch.setName("jbtnSearch"); // NOI18N

        bgSearchOptions.add(jrdByCode);
        jrdByCode.setSelected(true);
        jrdByCode.setText(bundle.getString("jrbByCode.title")); // NOI18N
        jrdByCode.setName("jrdByCode"); // NOI18N

        bgSearchOptions.add(jrdByName);
        jrdByName.setText(bundle.getString("jrbByName.title")); // NOI18N
        jrdByName.setName("jrdByName"); // NOI18N

        javax.swing.GroupLayout jpSearchFilmTypeLayout = new javax.swing.GroupLayout(jpSearchFilmType);
        jpSearchFilmType.setLayout(jpSearchFilmTypeLayout);
        jpSearchFilmTypeLayout.setHorizontalGroup(
            jpSearchFilmTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpSearchFilmTypeLayout.createSequentialGroup()
                .addGap(89, 89, 89)
                .addGroup(jpSearchFilmTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jpSearchFilmTypeLayout.createSequentialGroup()
                        .addComponent(jrdByCode)
                        .addGap(18, 18, 18)
                        .addComponent(jrdByName))
                    .addGroup(jpSearchFilmTypeLayout.createSequentialGroup()
                        .addComponent(jtxtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 308, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(36, 36, 36)
                        .addComponent(jbtnSearch, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(67, Short.MAX_VALUE))
        );
        jpSearchFilmTypeLayout.setVerticalGroup(
            jpSearchFilmTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpSearchFilmTypeLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpSearchFilmTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jtxtSearch, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtnSearch))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jpSearchFilmTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jrdByCode)
                    .addComponent(jrdByName))
                .addContainerGap(12, Short.MAX_VALUE))
        );

        jpListFilmType.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("jpListSearchForm.title"))); // NOI18N
        jpListFilmType.setName("jpListFilmType"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jtbFilmTypes.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Nums", "Code", "Name"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jtbFilmTypes.setName("jtbFilmTypes"); // NOI18N
        jtbFilmTypes.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane1.setViewportView(jtbFilmTypes);

        javax.swing.GroupLayout jpListFilmTypeLayout = new javax.swing.GroupLayout(jpListFilmType);
        jpListFilmType.setLayout(jpListFilmTypeLayout);
        jpListFilmTypeLayout.setHorizontalGroup(
            jpListFilmTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpListFilmTypeLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 604, Short.MAX_VALUE)
                .addContainerGap())
        );
        jpListFilmTypeLayout.setVerticalGroup(
            jpListFilmTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpListFilmTypeLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 143, Short.MAX_VALUE)
                .addContainerGap())
        );

        jpDetailFilmType.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("jpFilmTypeDetailForm.title"))); // NOI18N
        jpDetailFilmType.setName("jpDetailFilmType"); // NOI18N

        jLabel1.setText(bundle.getString("jlbCode.title")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jtfCodeId.setName("jtfCodeId"); // NOI18N

        jLabel2.setText(bundle.getString("jlbTypeName.title")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jtfTypeName.setName("jtfTypeName"); // NOI18N

        jLabel3.setText(bundle.getString("jlbDetailedDescription.title")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jScrollPane2.setName("jScrollPane2"); // NOI18N

        jtaDetailDescription.setColumns(20);
        jtaDetailDescription.setRows(5);
        jtaDetailDescription.setName("jtaDetailDescription"); // NOI18N
        jScrollPane2.setViewportView(jtaDetailDescription);

        jbtnReset.setText(bundle.getString("jbtnReset.title")); // NOI18N
        jbtnReset.setName("jbtnReset"); // NOI18N

        jbtnAddType.setText(bundle.getString("jbtnAddType.title")); // NOI18N
        jbtnAddType.setName("jbtnAddType"); // NOI18N

        jbtnUpdateType.setText(bundle.getString("jbtnUpdateType.title")); // NOI18N
        jbtnUpdateType.setName("jbtnUpdateType"); // NOI18N

        jbtnDeleteType.setText(bundle.getString("jbtnDeleteType.title")); // NOI18N
        jbtnDeleteType.setName("jbtnDeleteType"); // NOI18N

        jbtnCancel.setText(bundle.getString("jbtnCancel.title")); // NOI18N
        jbtnCancel.setName("jbtnCancel"); // NOI18N

        javax.swing.GroupLayout jpDetailFilmTypeLayout = new javax.swing.GroupLayout(jpDetailFilmType);
        jpDetailFilmType.setLayout(jpDetailFilmTypeLayout);
        jpDetailFilmTypeLayout.setHorizontalGroup(
            jpDetailFilmTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpDetailFilmTypeLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpDetailFilmTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel3)
                    .addComponent(jLabel2)
                    .addComponent(jLabel1))
                .addGap(32, 32, 32)
                .addGroup(jpDetailFilmTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfTypeName, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jtfCodeId, javax.swing.GroupLayout.PREFERRED_SIZE, 163, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(152, 152, 152)
                .addGroup(jpDetailFilmTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(jbtnReset, javax.swing.GroupLayout.DEFAULT_SIZE, 171, Short.MAX_VALUE)
                    .addComponent(jbtnAddType, javax.swing.GroupLayout.DEFAULT_SIZE, 171, Short.MAX_VALUE)
                    .addComponent(jbtnUpdateType, javax.swing.GroupLayout.DEFAULT_SIZE, 171, Short.MAX_VALUE)
                    .addComponent(jbtnDeleteType, javax.swing.GroupLayout.DEFAULT_SIZE, 171, Short.MAX_VALUE)
                    .addComponent(jbtnCancel, javax.swing.GroupLayout.DEFAULT_SIZE, 171, Short.MAX_VALUE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jpDetailFilmTypeLayout.setVerticalGroup(
            jpDetailFilmTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpDetailFilmTypeLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jpDetailFilmTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jtfCodeId, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtnReset))
                .addGap(18, 18, 18)
                .addGroup(jpDetailFilmTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(jtfTypeName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbtnAddType))
                .addGap(18, 18, 18)
                .addGroup(jpDetailFilmTypeLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jLabel3)
                    .addGroup(jpDetailFilmTypeLayout.createSequentialGroup()
                        .addComponent(jbtnUpdateType)
                        .addGap(18, 18, 18)
                        .addComponent(jbtnDeleteType)
                        .addGap(18, 18, 18)
                        .addComponent(jbtnCancel))
                    .addComponent(jScrollPane2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jpListFilmType, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jpDetailFilmType, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jpSearchFilmType, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jpSearchFilmType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jpListFilmType, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(18, 18, 18)
                .addComponent(jpDetailFilmType, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup bgSearchOptions;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JButton jbtnAddType;
    private javax.swing.JButton jbtnCancel;
    private javax.swing.JButton jbtnDeleteType;
    private javax.swing.JButton jbtnReset;
    private javax.swing.JButton jbtnSearch;
    private javax.swing.JButton jbtnUpdateType;
    private javax.swing.JPanel jpDetailFilmType;
    private javax.swing.JPanel jpListFilmType;
    private javax.swing.JPanel jpSearchFilmType;
    private javax.swing.JRadioButton jrdByCode;
    private javax.swing.JRadioButton jrdByName;
    private javax.swing.JTextArea jtaDetailDescription;
    private javax.swing.JTable jtbFilmTypes;
    private javax.swing.JTextField jtfCodeId;
    private javax.swing.JTextField jtfTypeName;
    private javax.swing.JTextField jtxtSearch;
    // End of variables declaration//GEN-END:variables
}
